0

I have one div when I click that div I want to open a child browser.I have the code for child browser but when I click the div it executes the javascript line and I didn't get any url from there. Please check my code

Div code

  <div class="box_padding " onClick="window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes);return false;" id="column-c-box-1" >

  <script type="text/javascript"  src="http://ad.leadboltads.net/show_app_ad.js?section_id=838333320"></script>

  </div>

when I tried this nothing happening.

So I have tried one more way to solve this issue

  function openwindow(){
            w=open("myurl",'windowname','width=600,height=250,scrollbars,resizable,toolbar,status');
            with(w.document){
                write("<body>");
                write("This is a new window");
                write("</body>");
            }
            return false;
        }

HTML:

<div class="box_padding "onClick="openwindow();" id="column-c-box-1" >
 <script type="text/javascript"  src="http://ad.leadboltads.net/show_app_ad.js?section_id=838333320"></script>
</div>

This is also not working.

Roopendra
  • 7,674
  • 16
  • 65
  • 92
Bangalore
  • 1,572
  • 4
  • 20
  • 50

2 Answers2

1

If you have jquery available you can use this instead of this.href:

$('script').attr('src');

function openwindow(){
            w=open($(this).find('script').attr('src'),'windowname','width=600,height=250,scrollbars,resizable,toolbar,status');
            with(w.document){
                write("<body>");
                write("This is a new window");
                write("</body>");
            }
            return false;
        }
sitesbyjoe
  • 1,861
  • 15
  • 21
1

This seems to work in a preliminary test, native javascript. This would be trivial w/ jquery as a previous poster has shown.

Use the URL as a parameter in the div tag "srcVal".

<div class="box_padding " srcVal="http://ad.leadboltads.net/show_app_ad.js?section_id=838333320"  onClick="openwindow()" id="column-c-box-1">click me</div>

or this way:

<div class="box_padding "onClick="openwindow();" id="column-c-box-1" >
 <script type="text/javascript"  src="http://ad.leadboltads.net/show_app_ad.js?section_id=838333320" id="scriptTag"></script>
</div>

Your function slightly modified:

function openwindow(){
    var id = document.getElementById("column-c-box-1").getAttribute("srcVal");  
    //or
    // var scr = document.getElementsByTagName('script');
    //var id = scr[0].src; // use scr[scr - 1].src if have multiple scripts
               var w=open(id,'windowname','width=600,height=250,scrollbars,resizable,toolbar,status');
                with(w.document){
                    write("<body>");
                    write("This is a new window");
                    write("</body>");
                }
                return false;
            }

I used "with" because that is in your original code, but I'd caution against it. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/with?redirectlocale=en-US&redirectslug=JavaScript%2FReference%2FStatements%2Fwith

james emanon
  • 11,185
  • 11
  • 56
  • 97
  • edited. had a bad "id" in there and fixed the second ref if wanting to use the "grab from script way"... though, that src took a veryyy long time to load. but eventually it did. – james emanon Feb 04 '14 at 20:54