how to access dom element using iframe for different domain url -
i want unique id of remoter url webpage inserted in iframe working fine local file eg aboutus.html (same domain) in other browser chrome not working in of browser remote url of different domain eg http://www.shopping.com
mainpage.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" /> <meta http-equiv="access-control-allow-origin" content="*"> <title>untitled document</title> <link rel="stylesheet" href="css/style.css" type="text/css" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script> $(document).ready(function() { $("#btn_show").click(function(){ if($("#txt_url").val() == "") { alert("enter url"); $("#txt_url").focus(); } else { var cururl = $("#txt_url").val(); $('#myframe').attr('src',$("#txt_url").val()); windows.frames['#myframe'].location.reload(); } }); $('#btn-clear').click(function(){ var htmltxt = document.getelementbyid("unique_sel_textbox"); $(htmltxt).val(''); }); $("#btn-inspect").click(function(){ var iframedoc = document.getelementbyid('myframe').contentwindow; $(iframedoc).mouseover(function(event){ $(event.target).css("outline","dashed 1px #000"); //addclass("set_outline"); }).mouseout(function(event){ $(event.target).css("outline",""); //removeclass("set_outline"); }).click(function(event){ $(event.target).css("border","0.1em solid #f00"); //addclass("outline-selected"); var uniqsel=""; var curid=""; var curcls=""; var pastecls=""; var pastepath = ""; var html_txt_id = document.getelementbyid('unique_sel_textbox'); /*if(((event.target).id) && ((event.target).classname)){ var mergidcls = '#' + ((event.target).id) + '.' + ((event.target).classname); alert(mergidcls); } else */ if((event.target).id){ if(((event.target).id) == 'undefined') curid=""; else { curid = '#' + ((event.target).id); html_txt_id.value += " " + curid; } } else if((event.target).classname){ if(((event.target).classname) == 'undefined') curcls = ""; else { var nodname = ((event.target).nodename).tolowercase(); curcls = '.' + ((event.target).classname); html_txt_id.value += " " + nodname + curcls; } } else { var curpath = getelementuniqueid(event.target); html_txt_id.value += curpath; } }); $( "#btn-inspect").unbind("click"); }); }); //get dom path of selected element function getelementuniqueid(element){ return $(element).parent().andself().map(function(){ var $this = $(this); var tagname = this.nodename; if($this.siblings(tagname).length >= 0){ tagname += ":nth-child(" + ($(this).prevall(tagname).length + 1) + ")"; } return tagname; }).get().join(" > ").tolowercase(); } </script> </head> <body> <div class="main-wrap"> <div class="header" style="text-align:center; height:50px;"> <h2> dom unique id </h2> </div> <div class="main-content"> <div class="left-panel" style="width:250px; float:left; margin:10px; text-align:center;"> <div class="enter-url"> <form id="frm-url" style="border:1px solid #ccc; border-radius:4px;"> <br> <br> <p> enter url </p> <input type="text" id="txt_url" style="width:170px"> <br> <br> <input type="button" value=" show " id="btn_show"/> <br> <br> </form> </div> <br /> <div class="html-element"> <form> <p> html elementes </p> <textarea cols="25" rows="10" name="console" id="unique_sel_textbox" readonly="readonly" style="resize:none;"> </textarea> <br /> <br /> <input type="button" value=" clear " id="btn-clear";/> <input type="button" value=" inspect " id="btn-inspect";/> </form> </div> </div> <div class="right-panel"> <iframe width="900" editable="true" frameborder="1" height="500" id="myframe" src="aboutus.html"> </iframe> <br /> <br /> <p> <b> please select , element , xpath of highlighted element </b> </p> </div> </div> <div class="footer" style="height:50px;"> </div> </div> </body> </html> aboutus.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 id="page_title">untitled document</title> </head> <body> <div style="height:150px; border:1px solid #999"> <div style="height:80px; border:1px solid #999; margin:5px;"> <div class="class-child" style="height:50px; margin:5px; border:1px solid #999;"> div - 1 </div> </div> </div> <div style="height:50px; border:1px solid #666"> div - 2 </div> <div class="class-child" style="height:50px; border:1px solid #333"> div - 3 </div> <div> <h3 id="heading - 3"> heading - 3 </h3> </div> <div class="divclasstest" style="height:50px; margin:5px; border:1px solid #333" > testing div class </div> </body> </html> if use remote url in iframe src="http://www.w3schools.com/" not working
help me how can resolve issues/guide me technology have use if knows it.
by timothy
Comments
Post a Comment