简体   繁体   English

单击按钮显示外部网页内容

[英]Display External Web Page Content on Button Click

Sorry if this question has been asked before, I have gone through the resources available and have still not found a solution to my problem. 抱歉,如果您之前曾提出过此问题,我已经浏览了所有可用资源,但仍未找到解决问题的方法。

I have an input field where the user enters their website, keyword, or industry, and when they click go they are redirected to semrush.com to view the data. 我有一个输入字段,用户可以在其中输入他们的网站,关键字或行业,然后单击“ go”将他们重定向到semrush.com以查看数据。

<form onsubmit="handlerSubmitForm(this);" class="widget-form" target="_parent" method="get" action="http://www.semrush.com/search.php">
        <input type="text" name="q" class="widget-form__input" placeholder="Domain, keyword or url">
        <input type="hidden" name="db" value="us">
                        <input type="hidden" name="ref" value="798325166">
                    <div class="widget-form__db">us</div>
        <button type="submit" class="widget-form__submit">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M14.7 13.3l-3.7-3.7c.6-.9 1-2 1-3.1 0-3-2.5-5.5-5.5-5.5s-5.5 2.5-5.5 5.5 2.5 5.5 5.5 5.5c1.2 0 2.2-.4 3.1-1l3.7 3.7c.2.2.5.3.7.3s.5-.1.7-.3c.4-.4.4-1 0-1.4zm-12.2-6.8c0-2.2 1.8-4 4-4s4 1.8 4 4-1.8 4-4 4-4-1.8-4-4z"/></svg>
        </button>
    </form>

Is there any way I can have this data display below the button once they click it? 单击按钮后,是否可以通过任何方式在按钮下方显示此数据? Instead of redirecting them to the semrush.com page? 而不是将其重定向到semrush.com页面?

I understand this can be accomplished using an iframe, 我了解可以使用iframe完成此操作,

<iframe id="myIframe" src="http://www.semrush.com/search.php" onLoad="iframeDidLoad();"></iframe>

but I don't know how to add the inputted data to the iframe src You can view the current code on JSFiddle 但我不知道如何将输入的数据添加到iframe src中。您可以在JSFiddle上查看当前代码
Any help would be very much appreciated. 任何帮助将不胜感激。

Use Ajax. 使用Ajax。 Serialize the form data and do a ajax call to that url, then populate the iframe with the page returned. 序列化表单数据并对该URL进行Ajax调用,然后使用返回的页面填充iframe。

 $("button").click(function(){
        $.ajax(
        {
        url: "http://www.semrush.com/search.php", 
        type:'get',
        data: $( "form" ).serialize(), //find a way to serialize form data. 
        success: function(result){

          //result is the full html page returned from this url. Then you can put this in a iframe

        }});
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM