JavaScript - New Window Without Onclick In Html
I'm trying to develop a simple script that opens a link in a new window when the link has rel="external" set. What I don't want is to add onclick="newWindow();" to the anchor tag itself.
Every example I'm finding though adds the onclick method to the HTML. Code: window.onload = newWindow(); function newWindow() { var anchors = document.getElementsByTagName("a"); for(var i = 0; i < anchors.length; i++) { if(anchors[i].rel == "external") { anchors[i].onclick = function () { return window.open(this); }; } } } Code: <a href="http://www.google.com/" rel="external">Click to open in new window</a> If anyone could help me or point me in the right direction, I'd greatly appreciateit. Similar TutorialsI'm trying to pass the URL of a link to a function, then delay opening the window. I get an undefined error. Any help would really be appreciated. Here is my code: PHP Code: <head> <script> function openWin(test) { setTimeout("window.open(test)", 5000); } </script> </head> <body> <a href="http://www.example.com" onClick="openWin(this); return false;">Test</a> </body> how can you do onclick="return getconfirm('do you want to logout?');" onClick="window.location('logout.asp');" on the same button , if confirm then go url else stay here ? thank you Ok, 'nother head-banger for the hardcore! I have a "contact us" <a> with the id 'contact' on the main page, which is supposed to change the source file of an iframe to the contact page. Except when I click on "contact us" nothing happens. I've tried to get this to work several different ways, and suspect that the problem is purely syntax, but I just haven't been able to figure it out. Here's the code: The snippet on the main page (index.html): Code: <div id="linkListContact" class="LinkList"> <img id="linkListContactBg" class="SideBarBgImg" src="Assets/Backgrounds/SideBar/ContactBg.png"></img> <span> <ul> <li> <div><a id="contact">Contact Us</a> </div> </li> </ul> </span> </div> ... and the relevant Javascript: Code: function setIFrame(frameSource) { document.getElementById('mainWindow').src = frameSource; } function setContactLink() { var contactURL = "http://katabasis.spreadshirt.com/shop/imprint" document.getElementById('contact').onclick = new Function ( "setIFrame( 'contactURL' )" ); } The setIFrame function is used to call the content initially when the page loads, and is working beautifully in that context. You can see the problem in action at the actual site: www.katabasis-apparel.com. Thanks. Using onclick=window.open function in js to open a pdf file link in a new popup window. Works fine to display the file onscreen, but not if the user wants to save the file client-side to their computer. The right-hand-button context menu for the mouse will allow the user to download, but the file saved will be a html dump file for the webpage and the name of the file will be that for the webpage. Of course I can use the easy <a href> method for download links and the mouse context menu options will be as expected, but I can only use target="-blank" or target="_self" . I need a popup window to open. Could use : oncontextmenu="alert('Left click the link to open, and then SAVE from with the pdf viewer') to advise users how to save the file, and could use "javascript: void(0)" to eliminate most mouse context menu options, so the user won't bother try. So how can I get a link to a file which can be viewed in a popup window and downloaded using mouse right-hand context menu? Any advice massively appreciated! I'm trying to figure out a way to put this in all js code with the onclick event handlers and the parameters. I have 3 links that switch the style of my page. Right now I have them working with inline event handlers. Here are my code snippets below. HTML: Code: <head> <link rel="stylesheet" href="style1.css" type="text/css" title="style1"/> <link rel="alternate stylesheet" type="text/css" href="style2.css" title="style2" /> <link rel="alternate stylesheet" type="text/css" href="style3.css" title="style3" /> </head> <div class="styleLinks"> <a href="#" id="style1" onclick="setStyleSheets('style1'); return false;">Style 1</a> <a href="#" id="style2" onclick="setStyleSheets('style2'); return false;">Style 2</a> <a href="#" id="style3" onclick="setStyleSheets('style3'); return false;">Style 3</a> </div> JS: Code: function setStyleSheets(title) { //set styles and set cookie var i; var attribute; var today = new Date(); var expDate = new Date(today.getTime() + 7*24*60*60*1000); var styleSelected = ""; if (title=="style2"){ styleSelected = "style2"; } else if (title=="style3"){ styleSelected = "style3"; } for(i=0; (attribute = document.getElementsByTagName("link")[i]); i++) { if(attribute.getAttribute("rel").indexOf("style") != -1 && attribute.getAttribute("title")) { attribute.disabled = true; if(attribute.getAttribute("title") == title) attribute.disabled = false; SetCookie ('style', styleSelected, expDate, "/"); } } } Hi guys, On the back of my image preview issue (which is now fixed) I am having another problem. I am trying to get a file upload that will allow you to preview the html page in a popup on the click of a button. Can this be done? I have the preview button that creates the popup but at the moment it only shows the name of the file that's to be uploaded. Code below Code: <html> <head> <title>File Uploading Form</title> </head> <body> <h3>File Upload:</h3> Select a file to upload: <br /> <form method='post' action='upload.php' enctype="multipart/form-data" class="pure-form"> <input type="file" name="files[]" multiple="multiple" id="files"> <input type="button" value="Preview" onclick="displayHTML(this.form)"> <input type='submit' value='Submit' class="pure-button pure-button-primary"/> </form> </body> </html> <script> function displayHTML(form) { var inf = form.files.value; win = window.open(", ", 'popup', 'toolbar = no, status = no'); win.document.write("" + inf + ""); } </script> Reply With Quote 01-24-2015, 04:56 PM #2 jmrker View Profile View Forum Posts Senior Coder Join Date Aug 2006 Location FL Posts 3,175 Thanks 39 Thanked 510 Times in 504 Posts Can you use the right-click button on your mouse and "View Source", or is this not what you are trying to do? Reply With Quote 01-24-2015, 06:58 PM #3 Foster View Profile View Forum Posts Regular Coder Join Date Nov 2011 Posts 268 Thanks 8 Thanked 4 Times in 4 Posts Not what I'm trying to do. I want to be able to click the button and the file that is waiting to be opened should pop up in a new window. Reply With Quote 01-24-2015, 09:51 PM #4 Old Pedant View Profile View Forum Posts Supreme Master coder! Join Date Feb 2009 Posts 28,310 Thanks 82 Thanked 4,754 Times in 4,716 Posts LOOK at your code! Code: <input type="file" name=" files[] " ...rest doesn't matter... > and var inf = form. files .value; Those are *NOT* the same name in JavaScript. Only in PHP would the be (sort of) the same (and not even quite so, there). Anyway, I don't see how you can expect an HTML file that is not yet uploaded to look the same this way as it will coming from the server. ONLY if it is restricted as follows could you get the : (a) only <img> tags that use COMPLETE URLs as their src= (that is, src="http://somesite.com/somepath/someimage.pn") (b) only href's (in any kind of tag) that use COMPLETE urls. (c) only <script> tags that use src= complete urls. (d) probably other things I didn't think of Any RELATIVE urls (e.g., <img src="/images/xxx.png"/>) will be relative TO THE CLIENT MACHINE, not to the server. And how that relative path works may vary from browser to browser. Offhand, I'd say this is not a good idea. I think you should allow the upload and then preview the uploaded file in a popup window, yes, and give the user the opportunity to delete the just-uploaded file from the server. i have the code: foreach($product_names as $product_row) { ?> <tr> <td > </td><td width='200px'><?php echo $product_row->getName();?></td> <td width='200px'><input type="checkbox" name="graphic[]" value="<?php echo $product_row->getId();?>" onclick="check()"/></td> <td width='200px'><input type="checkbox" name="text[]" value="<?php echo $product_row->getId();?>" onclick="check()"/></td> </tr> <?php } ?> and a submit button on the page. the i also have the javascript code for the onclick="check()" : <html> <head> <script type="text/javascript"> function check() { var graphics = document.getElementsByName("graphic[]"); for(i=0;i<graphics.length;i++) { if(graphics[i].checked) { if(document.getElementById('submit').style.display=='none') { document.getElementById('submit').style.display='block'; } } } var text = document.getElementsByName("text[]"); for(i=0;i<text.length;i++) { if(text[i].checked) { if(document.getElementById('submit').style.display=='none') { document.getElementById('submit').style.display='block'; } } } } </script> </head> so what all this means is i have two arrays of checkboxes for each product. as soon as i check any checkbox the submit button appears. i click on the submit button and i go to the next form. the problem now comes in if i click on the "back" button to go back to the previous page via the bwrowser..the submit button is disabled althou all my checkboxes that i checked, are still checked....i want the submit button to show??? please help?? thanks HTML TARGET: Code: <div id="login_link" style="margin-top:-142px;margin-left:245px;height:142px;"> <img id="login_link" src="menu_button.png" /><a href="#"><img src="menu_button.png" /></a></div> </div> I'm trying to get menu_button.png to change to menu_button2.png on mouseover... I'd also like it to play a sound on click like "click.wav" I can't rename the div because it controls the slider Heres my current project table: http://bit.ly/dbwH23 I tried to put it in a span and have the span referance to the next tag but it didn't seem to work at least not in firefox. I'm going to keep lookin around but i'm not used to these types of code structure. I was thinking of Embeding a flash file inside the div instead but that might be overkill. Anyone know of a solution that might work? I have a web page with two forms, when I click the button on one of the forms, the onclick event goes to a javascript that emails the first form and then the second form. This is correct, this is the way I want this to work. It's simple, it's easy, it works! However, it only works in FireFox and Internet Explorer, it will not work in Google Chrome browser. I've spent many hours trying lots of various ways to implement this so I'm not interested in speculating about possible solutions that might work, I've already tried too many of those. Also, it needs to work this way, not combining the forms, etc. Does anyone have any tried and tested solutions that work with Chrome? Thanks, in advance, for your expert advice. I know I can always rely on EE when all else fails. I know somebody here can solve this problem. Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=windows-1250"> <title></title> </head> <body> <form id="NameForm" method="post" action="mailto:yourFirstemail@email.com"> Name: <input type="text" size="10" name="name"> <br /> <input onclick=functionCaller() type="button" value="Submit Two Forms"> </form> <form id="AddressForm" name="DComments" method="post" action="mailto:yourSecondemail@email.com"> Address: <input type="text" size="10" name="address"> <br /> </form> <script type="text/javascript"> <!-- function functionCaller() { document.getElementById('NameForm').submit(); document.getElementById('AddressForm').submit(); } --> </script> </body> </html> Here is my scenario, i have a html that allows the user to retrieve .pdf file from the server. If the users are trying to open the html again, mean the user open a new tab/window to the same html url, the window will prompt the user that the html is already opened. The user will need to close the old html tab/window first before open a new one. Is it possible to stop the users to open the new same html file before he/she closes the old one ? Is there any link that teach the tutorial about this ? I am wondering do i need to use cookies in the browser to store the url in order to compare to the new tab/window url ? Thanks for helping. I appreciate this a lot. hi I am making a multimedia Cd presentation in Html and I was wondering if there is any way for the index.html to autorun not in a browser, but only in window without any buttons - like a popup widow ? I really need help, i am looking for solution for 3 days now, and I need this to be done tomorrow.. thanx Hi EveryBody, I want to add a preview of html page feature in my project. I had created registration form and I need when user click submit button,user should get a preview of registration form after that further operation will b performed. Guys just tell me how can i achieved this. Any clue or sample code so i can learn it and implement in my project. Hi guys, I have been working on this and cant figure it out. I have an index.html as my main file and I wanted to have a pop-up window that will also open together with the index file. the pop-up window is a notepad like type, file name is clipboard.html. Addon: i started adding code to have the pop-up to stay on the right side of the screen and always on top. As of right now, all codes are very confusing and i decided to delete and start from scratch. Can you guys fill in the blanks? I'm writing a small browser-side Javascript that parses XML from a file and modifies it using E4X. I need to get the result to an xml text file without making the user go through a dozen hoops. Since making a JS client do file I/O is nearly impossible I gave up on that. My next idea was to make Firefox open a new window of contentType text/xml, with my serialized xml in it: Code: var xmlDoc = new XML(SourceXMLString); //SourceXMLString is read from an xml text file output = window.open(""); output.document.open("text/xml"); output.document.write(xmlDoc.toXMLString()); output.document.close(); However any document.write instance seems to set the contentType to text/html and so all the tags are rendered wrong, naturally. From https://bugzilla.mozilla.org/show_bug.cgi?id=73409 it seems that document.open creates the right contentType, but document.write messes it up. Note: this is for a specific internal project, not the public internet. Therefore it only needs to work in Mozilla 3+, and also server-side is not an option. I'm totally open to other suggestions. What's the most streamlined/easiest way, for the code and the user, to get from that XML construct to an .xml file? This is what I have so far which prompts the user three numbers and then displays the max of the numbers and all three of them. Now the last thing I was wanting to do is change it from three prompts to just one prompt. How could I prompt to type in three numbers in one prompt and get the max from those three numbers.? Any help would be greatly appreciated. Thank you in advance! Code: <head> <title>Maximum Number</title> </head> <body> <center><h2>Maximum Number</h2> <script language="Javascript" type="text/javascript"> function Max(num1, num2,num3) { var largest=arguments[num1, num2, num3] for (i=0; i<arguments.length; i++) { if ((num1>num2)&&(num1>num3)) largest=num1 else if((num2>num1)&&(num2>num3)) largest=num2 else largest=num3 } return(largest) } document.write("</br>") var num1=prompt("Enter the first number: ", "") var num2=prompt("Enter the second number: ", "") var num3=prompt("Enter the third number: ", "") var max= Max(num1, num2, num3) document.write("You entered: ", num1, ", ", num2, ", ", num3) document.write("</br>") document.write("The Maximum number is: ", max) </script></center> </body> </html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script language="Javascript" type="text/javascript"> function user_prompt() { alert.("Hello there"); } user_prompt(); </script> </head> <body> </body> </html> I am such a noob. But I am so bad I cannot even get a window alert to pop up. All I want to do is call the function in the body. But do not know how... I have an HTML page that is making use of JQUERY and many other JQUERY plugins. Inside this HTML page there are 2 different types of iFrames that display PHP forms. One is a normal iFrame: Code: <iframe height="740" allowTransparency="true" frameborder="0" scrolling="auto" style="width:100%;border:none;overflow-x:hidden" src="https://www.website.com/machform/embed.php?id=9" title="Contact Us"><a href="https://www.website.com/machform/view.php?id=9" title="Contact Us">Contact Us</a></iframe> The other makes use of a JQUERY plugin called Shadowbox: Code: <a href="https://www.website.com/machform/embed.php?id=8" rel="shadowbox;width=1100;height=950;player=iframe" class="button1"><span></span><strong>Click Here</strong></a> Inside these iFrames are PHP forms from a PHP form application called MachForm, which is highly customizable. Here are the questions. Ultimately, I want to accomplish 2 things: 1. I would like to send variable information from the PHP form in the iFrame to my HTML page, to be displayed within javascripts. For example: If someone fills out a PHP form in my iFrame and clicks submit, I want to have a JQUERY popup say, "Thank you, [NAME]". 2. When the user submits the form, the action of clicking the submit button in the PHP form should enable #1, above. There needs to be a way to tell the HTML/Javascript that the submit button on the PHP form in the iFrame has been clicked. I realize this is all fairly vague, especially without the addition of more code. However, I am not even sure if I am posting this in the correct forum, since it incorporates a little of several languages and styles. From this point any direction or idea would be very helpful! Hi there, I am trying to open some SWF videos from an HTML page. When the user clicks the link, I would like to have the videos open in a transparent window (not a separate browser wndow). I have figured out how to embed the files and have them open in a transparent window as soon as you load/refresh the page but I want to open the SWF using a link. Any suggestions? Thank you all. B |