Get HTML inside iframe using jQuery

后端 未结 10 1156
清歌不尽
清歌不尽 2020-11-27 04:24

Here is my situation.

I have a file called iframe.html, which contains the code to for a image slideshow. The code is somewhat like

<         


        
10条回答
  •  渐次进展
    2020-11-27 04:52

    Why not try Ajax, check a code part 1 or part 2 (use comment).

    $(document).ready(function(){ 
    	console.clear();
    /*
        // PART 1 ERROR
        // Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Sandbox access violation: Blocked a frame at "http://stacksnippets.net" from accessing a frame at "null".  Both frames are sandboxed and lack the "allow-same-origin" flag.
    	console.log("PART 1:: ");
    	console.log($('iframe#sandro').contents().find("html").html());
    */
    	// PART 2
    	$.ajax({
    		url: $("iframe#sandro").attr("src"),
    		type: 'GET',
    		dataType: 'html'
    	}).done(function(html) {
    		console.log("PART 2:: ");
    		console.log(html);
    	});
    
    });
    
    
    
    
    
    

提交回复
热议问题