Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: javascript not to open in new window

  1. #1
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    892
    Thanks
    112
    Thanked 2 Times in 2 Posts

    Default javascript not to open in new window

    I ran into a script that fits my needs, but there's just one thing. The code makes it open in a new window, where I also have to write the headers.

    Is it possible to have the script open in the same window, with the same headers as the page where the script is activated from (so it replaces the form where this script gives the results of).

    Here's the original code:
    Code:
    var newWindow;
    var newContent = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><title>here's my title</title><link rel=\"stylesheet\" type=\"text/css\" href=\"css/style.css\" media=\"screen\" /></head><body><div class=\"container margin-top-70 margin-bottom-90\"><div class=\"row margin-bottom-60\"><div class=\"col-md-12\">";
    
    function makeNewWindow(){
    newWindow = window.open("", "numbers", "");
    }
    and a bit further:
    Code:
    newContent += "</body>\n</html>";
    newWindow.document.write(newContent); 
    newWindow.document.close()  
    }}
    
    newContent += "</div></div></div></body></html>";
    Here's the full js file: https://www.lichaamengeest.be/scripts/numerologie.js
    Something to do with window.location.href, but can anyone help me out, please? Thanks!

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,497
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Yeah, get rid of the new header and the opening body tag (remove highlighted):

    Code:
    var newContent = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><title>Lichaam en Geest: De duiding van jouw geboortegetal</title><link rel=\"stylesheet\" type=\"text/css\" href=\"https://lichaamengeest.be/css/style.css\" media=\"screen\" /></head><body><div class=\"container margin-top-70 margin-bottom-90\"><div class=\"row margin-bottom-60\"><div class=\"col-md-12\">";

    Then get rid of, or comment out as shown, the highlighted and add the red:

    Code:
    // makeNewWindow();
    newContent += "<a href=\"javascript: window.close()\" class=\"button border\"> Klik hier om dit venster te sluiten en terug te keren naar Lichaam en Geest</a>"
    newContent += "<br>";
    newContent += "<br>";
    newContent += "<h3>Hieronder vind je een gedetailleerde duiding van jouw numerologisch geboortegetal<br>- gemaakt op " + weekday[dag.getDay()] + "&nbsp;";
    newContent += dag.getDate() + "-";
    newContent += monthname[dag.getMonth()] + "-";
    newContent += dag.getFullYear();
    newContent += "<br>";
    
    //alert(Orakel());
    
    Orakel();
    
    // newContent += "</body>\n</html>";
    // newWindow.document.write(newContent);  // schrijf alles naar het scherm
    // newWindow.document.close()   //schijnt zo te moeten
    ;(function(){
    	var div = document.createElement('div'), frm = document.forms[0], trg = frm.parentNode;
    	trg.insertBefore(div, frm);
    	trg.removeChild(frm);
    	div.innerHTML = newContent;
    })();
    }}
    Oh, and you should probably get rid of this line too:

    Code:
    window.location.reload()
    But it probably doesn't matter.

    If you want more help please link to the problematic page.
    Last edited by jscheuer1; 02-26-2018 at 04:09 PM. Reason: add info
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    chechu (02-26-2018)

  4. #3
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    892
    Thanks
    112
    Thanked 2 Times in 2 Posts

    Default

    Thanks for that, John.
    Still one issue.

    Here's the test page and here's the adjusted js

    You'll see that the content shows and does push the rest (footer) down, but the form disappears.
    How can that be solved?

    Maybe this should be removed also,
    on line 2:
    Code:
    var newWindow;
    and on line 5-6-7:
    Code:
    function makeNewWindow(){
      newWindow = window.open("", "uitslag", "");
    }
    Could you please help me out?
    Thanks.
    Last edited by chechu; 02-26-2018 at 06:00 PM.

  5. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,497
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I thought you said you wanted it to replace the form.

    Is it possible to have the script open in the same window, with the same headers as the page where the script is activated from (so it replaces the form where this script gives the results of).
    As for pushing the footer down, it's going to do that because there's more content there than the form had, and there was some space there before submitting the form. But I also see some extra empty space. That extra space appears to come from class names (and their associated styles) in the generated markup. You can get rid of the extra space by removing the highlighted:

    Code:
    var newContent = "<div class=\"container margin-top-70 margin-bottom-90\"><div class=\"row margin-bottom-60\"><div class=\"col-md-12\">";
    You can also get rid of the two things you mentioned, but that won't change anything. They're no longer used. I left them in case it became desirable to revert to the original method.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #5
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    892
    Thanks
    112
    Thanked 2 Times in 2 Posts

    Default

    You're right, John, I didn't express myself correctly, sorry.
    Is it possible to have the content show below the form, so, if needed, the form can be filled in again, please?
    And how can the content "break out" of the divs of the form (md-6) so it shows below full width (md-12)?
    Thanks.

    * please refresh the page, as I just replaced the js and left the html untouched: now it doesn't push the footer down and stays in the same div.
    Last edited by chechu; 02-26-2018 at 08:22 PM.

  7. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,497
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    OK, then I'd replace:

    Code:
    ;(function(){
    	var div = document.createElement('div'), frm = document.forms[0], trg = frm.parentNode;
    	trg.insertBefore(div, frm);
    	trg.removeChild(frm);
    	div.innerHTML = newContent;
    })();
    with:

    Code:
    ;(function(){
    	var div, ft, trg;
    	if(document.getElementById('aanumbersresults')){div = document.getElementById('aanumbersresults');}
    	else {
    		div = document.createElement('div'); ft = document.getElementById('footer'); trg = ft.parentNode;
    		div.id = 'aanumbersresults';
    		trg.insertBefore(div, ft);
    	}
    	div.innerHTML = newContent;
    })();
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #7
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    892
    Thanks
    112
    Thanked 2 Times in 2 Posts

    Default

    Now nothing comes up.
    Should I replace "aanumbersresults" in your code by something else?

  9. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,497
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I probably just made a typo. Let me check.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,497
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Actually I think you made a typo. Where you now have:

    Code:
    ;(function(){
    	var div, ft, trg;
    	if(document.getElementById('aanumbersresults')){div = document.getElementById('aanumbersresults');}
    	else {
    		div = document.createElement('div'); ft = document.getElementById('footer'); trg = ft.parentNode;
    		div.id = 'aanumbersresults';
    		trg.insertBefore(div, ft);
    	}
    	div.innerHTML = newContent;
    })();
    Looks like you left out the closing braces for the two parent functions (they were there before), so add those back in (red):

    Code:
    ;(function(){
    	var div, ft, trg;
    	if(document.getElementById('aanumbersresults')){div = document.getElementById('aanumbersresults');}
    	else {
    		div = document.createElement('div'); ft = document.getElementById('footer'); trg = ft.parentNode;
    		div.id = 'aanumbersresults';
    		trg.insertBefore(div, ft);
    	}
    	div.innerHTML = newContent;
    })();
    }}
    Pretty sure that's it (the error I see in the console indicates that's likely). If not, revert from a backup and I'll look again.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  11. The Following User Says Thank You to jscheuer1 For This Useful Post:

    chechu (02-26-2018)

  12. #10
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    892
    Thanks
    112
    Thanked 2 Times in 2 Posts

    Default

    Indeed my mistake.
    Now it works lovely: I type in a date and it shows below.
    But when I want to check on another date, then that shows below the explanation of the first date, and so on.
    Actually if I search a second date, then the explanation of the first date should disappear.
    Hopefully you understand what I mean?

Similar Threads

  1. javascript:window.open
    By Pinky in forum HTML
    Replies: 11
    Last Post: 08-29-2009, 08:54 PM
  2. Replies: 2
    Last Post: 03-14-2009, 05:32 PM
  3. Open javascript link in same window
    By weezle in forum JavaScript
    Replies: 2
    Last Post: 02-07-2009, 05:12 PM
  4. New window open in JavaScript
    By Neal in forum JavaScript
    Replies: 5
    Last Post: 03-12-2008, 04:21 AM
  5. window.open() :- javascript
    By manashi_130582 in forum JavaScript
    Replies: 3
    Last Post: 04-26-2006, 06:39 AM

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
  •