2017-04-23 11 views
1

クラスのプロジェクトで作業しています。ページの読み込み時にポップアップを表示し、ユーザーが移動したときにポップアップを表示するjavascriptイベントが必要です。私はonloadonunloadのイベントをHTMLに直接埋め込んで処理しようとしていますが、クロムとインターネットエクスプローラで動作しているようには見えません。アンロードメッセージしか表示されません。コードは以下の通りである:ページのJavaScriptのアラートページ終了時のロードとアラート

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
    <meta charset="utf-8"> 
    <title>teest</title> 
    <!-- [if lt IE 9]> 
    <script src = "http://html5shim.googlecode.com/svn/trunk/html5.js"></script> 
    <![endif] --> 
    <link rel="stylesheet" href="css/contact.css" /> 
    <meta name="viewport" content="width=device-width,initial-scale=1.0"> <!-- viewport tag configuration --> 
    <link rel="shortcut icon" href="img/favicon.ico" /> 
    </head> 
    <body onload = "alert('Even if you aren't interested, please give our design some feedback as we would like to stay current.')" onunload = "alert('Thank you for your time and consideration!')"> 
     <header class = "head"> 
      <h1> 
      <img src="img/coa.png" display="inline-block" height="150px" float="left"/> 
      other stuff</h1> 
      <p>stuffsy</p> 
     </header> 

+0

可能な重複したり、文字列の正しい方法を認識します

'Even if you aren\'t interested, please give our design some feedback as we would like to stay current.' 

にそれを変更する必要がありますページリフレッシュ?](http://stackoverflow.com/questions/13443503/run-javascript-code-on-window-close-or-page-refresh) – Bassie

+0

[アンロードイベントのドキュメント](https:// developer .mozilla.org/ja-US/docs/Web/Events/unload)では、「UI interアクションは効果がありません(window.open、alert、confirmなど) "ので、onunloadでalertを使用することはできません。 – user2313067

答えて

3

アラートにあなたの引用符をエスケープする必要があります。
あなたの現在の文字列は

'Even if you aren't interested, please give our design some feedback as we would like to stay current.' 

であり、あなたは、だから、

窓の近くの[ファイル名を指定して実行するJavaScriptコードの
+0

'onunload()'イベントがクロームで動作しないように思われる理由はありますか? – Callat

+1

オンロードイベントで警告メッセージを自動的にブロックするChrome https://i.stack.imgur.com/ihX2X.png –

+0

ああ、ありがとうございます。私の割り当てがそれを要求するので、回避策を見つける必要があります。 – Callat

関連する問題