SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    question in JavaScript, browser blocking my functions

    Hello everyone.
    Sorry if I post in wrong place, there were no section for newbies in .js forum

    Can someone explain why chrome and IE blocking my javascript code? javascript is enabled in both, and .js from other website's works well ...

    Here's my code:

    Code:
    <!doctype html>
    <html>
    <head>
    	<title>Your page title</title>
    	<meta name="description" content="page_description">
    	<meta name="keywords" content="keyword1, keyw2, keyw3">
    	<meta name="author" content="MrPaulius">
    	<meta charset="utf-8">
    	<link rel="stylesheet" href="style.css">
    	<script type="text/javascript" src="java.js"></script>
    </head>
    
    <body>
    
    	<form>
    		<input type="text" name="inputA" id="inputA" size="4">
    		<input type="text" name="inputB" id="inputB" size="4">
    		<input type="button" value="Add up" onclick="newWindow()">
    	</form>
    
    </body>
    </html>
    
    
    
    function newWindow(){
    	window.open();
    }
    Last edited by Pullo; Jul 24, 2013 at 14:10. Reason: Added code tags

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,889
    Mentioned
    210 Post(s)
    Tagged
    12 Thread(s)
    Hi,

    Your JavaScript needs to be within <script> tags, ideally just before the closing </body> tag.

    Like this:

    Code:
        <script>
          function newWindow(){
            window.open();
          }
        </script>
      </body>
    </html>
    HTH

  3. #3
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry forgot to mention, js code is in external file.

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,788
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    If it is in an external file then that file needs to be attached into the HTML with a script tag just before the </body>
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is attached in head, isint that where it supposed to be?
    My IE says that it restricted page from running scripts or ActiveX controls.

    Once i allow it, js works. I can understand why.. js works properly in other websites.

  6. #6
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,035
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)
    I'm guessing it's because the js wants to open a window and the browsers are warning you.

    Maybe there are some option settings like "allow script to ..." somewhere you need to change?

  7. #7
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,889
    Mentioned
    210 Post(s)
    Tagged
    12 Thread(s)
    With IE, you will need to allow the JS to run explicitly when you are running the file locally.
    I haven't tried this, but according to Google you can up enable Active Content from local files in the advanced tab of the Internet Options.
    HTH

  8. #8
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, at least i know now there is nothing rong with my code thanks guys for help


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •