使用Javascript重定向到特定URL

时间:2017-11-15 15:12:08

标签: javascript jquery html

我想要做的很简单,假设我有一个类似于此 <object class="GtkFileChooserDialog" id="file_chooser"> <property name="can_focus">False</property> <property name="modal">True</property> <property name="type_hint">dialog</property> <property name="select_multiple">True</property> <child internal-child="vbox"> <object class="GtkBox"> <property name="can_focus">False</property> <property name="orientation">vertical</property> <property name="spacing">2</property> <child internal-child="action_area"> <object class="GtkButtonBox"> <property name="can_focus">False</property> <property name="layout_style">end</property> <child> <object class="GtkButton" id="button1"> <property name="label">gtk-cancel</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> <property name="use_stock">True</property> </object> <packing> <property name="expand">True</property> <property name="fill">True</property> <property name="position">0</property> </packing> </child> <child> <object class="GtkButton" id="button2"> <property name="label">gtk-open</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> <property name="use_stock">True</property> </object> <packing> <property name="expand">True</property> <property name="fill">True</property> <property name="position">1</property> </packing> </child> </object> <packing> <property name="expand">False</property> <property name="fill">False</property> <property name="position">0</property> </packing> </child> <child> <placeholder/> </child> </object> </child> <action-widgets> <action-widget response="-1">button1</action-widget> <action-widget response="-5">button2</action-widget> </action-widgets> </object> 的网址来自网址,它可以像 / pro?type = beans / pro?type = rice ,我想要的是让URL将其重定向到这样的https://www.example.com/pro?type=oil请第一个网址是/ pro?重定向位置是/ zpro?谢谢。

2 个答案:

答案 0 :(得分:2)

如果我理解你想要什么,下面应该这样做。

window.location.href = window.location.href.replace('/pro?', '/zpro?')

答案 1 :(得分:2)

因此,您可以使用window.location.href来访问当前网址的字符串。通过将其设置为新值,您可以更改当前URL!所以对你来说,这意味着设置window.location.href = window.location.href.replace('/pro', '/zpro')。这将使您的网址中的字符串/pro重定向到/zpro,同时保持您的查询参数完好无损!